﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Prsrp
{
    public static class MouseManager
    {
        /// <summary>
        /// The mouse state of the frame before current frame.
        /// </summary>
        private static MouseState mpOldMouseState;
        public static MouseState OldKeyboardState
        {
            get { return mpOldMouseState; }
        }

        /// <summary>
        /// The mouse state of the current frame.
        /// </summary>
        private static MouseState mpCurMouseState;
        public static MouseState CurMouseState
        {
            get { return mpCurMouseState; }
        }

        public static bool IsLeftButtonDragging()
        {
            return (
                mpOldMouseState.LeftButton == ButtonState.Pressed && 
                mpCurMouseState.LeftButton == ButtonState.Pressed
            );
        }

        /// <summary>
        /// Basic Update function.
        /// </summary>
        public static void UpdateMouseState()
        {
            mpOldMouseState = mpCurMouseState;
            mpCurMouseState = Mouse.GetState();
        }

        /// <summary>
        /// Return true if left mouse button is clicked.
        /// </summary>
        public static bool IsLeftMouseButtonClickedOnce()
        {
            return (
                mpCurMouseState.LeftButton == ButtonState.Pressed &&
                mpOldMouseState.LeftButton == ButtonState.Released
            );
        }

        /// <summary>
        /// Return true if right mouse button is clicked.
        /// </summary>
        public static bool IsRightMouseButtonClickedOnce()
        {
            return (
                mpCurMouseState.RightButton == ButtonState.Pressed &&
                mpOldMouseState.RightButton == ButtonState.Released
            );
        }

        /// <summary>
        /// Return mouse position at the current frame as a Vector2 value.
        /// </summary>
        public static Vector2 GetCurMousePos()
        {
            return new Vector2(mpCurMouseState.X, mpCurMouseState.Y);
        }

        /// <summary>
        /// Return mouse position at the previous frame as a Vector2 value.
        /// </summary>
        /// <returns></returns>
        public static Vector2 GetOldMousePos()
        {
            return new Vector2(mpOldMouseState.X, mpOldMouseState.Y);
        }
    }
}
